﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data.SqlClient;
using System.Collections;

namespace Electure.DAL
{
    public enum ScienceDepartmentType : int
    {
        Faculty = 1,
        Institute = 2,
        Department = 3
    }
    public class ScienceDepartment : BaseModel
    {
        public string Name { get; set; }
        public ScienceDepartmentType Type { get; set; }
    }

    public class ScienceDepartmentRepository : BaseRepository<ScienceDepartment>
    {
        internal ScienceDepartmentRepository() { }
        protected override int create(ScienceDepartment instance)
        {
            return connection.Execute("INSERT INTO ScienceDepartment(Name,Type) VALUES (@Name, @Type)", instance);
        }
        public override bool Update(ScienceDepartment instance)
        {
            return connection.Execute("UPDATE ScienceDepartment SET name=@Name, Type=@Type WHERE id = @ID", instance) == 1;
        }
        public override bool Delete(int id)
        {
            return connection.Execute("DELETE FROM ScienceDepartment WHERE ID = @id", new { id = id }) == 1;
        }
        public override List<ScienceDepartment> GetAll()
        {
            return connection.Query<ScienceDepartment>("SELECT * FROM ScienceDepartment").ToList();
        }
    }
}
